package com.wanghengzhi.kata;

/**
 *
 * @author wanghengzhi
 * @since 2021/11/7 21:19
 */
public abstract class Goods {
    private static final int MIN_GOODS_VALUE = 0;
    private static final int MAX_GOODS_VALUE = 50;
    private final String name;
    protected double quality;
    protected int sellIn;

    public Goods(String name, double quality, int sellIn) {
        this.name = name;
        this.quality = quality;
        this.sellIn = sellIn;
    }

    abstract void updateByDay();

    protected void decreaseSellInByOne() {
        sellIn = sellIn - 1;
    }

    protected void decreaseByOneIfQualityGreatThanZero() {
        if (quality > MIN_GOODS_VALUE) {
            quality = quality - 1;
        }
    }

    protected void increaseByOneIfQualityLessThanFifty() {
        if (quality < MAX_GOODS_VALUE) {
            quality = quality + 1;
        }
    }

    public double getQuality() {
        return quality;
    }

    public int getSellIn() {
        return sellIn;
    }

    @Override
    public String toString() {
        return "Goods{" +
                "name='" + name + '\'' +
                ", quality=" + quality +
                ", sellIn=" + sellIn +
                '}';
    }
}
